
<?php
use app\backend\widgets\LinkPager;
use app\backend\components\AppAdminAcl;
use yii\helpers\Url;
$this->title = '用户管理';
$this->params['breadcrumbs'] = [['label' => '用户']];
?>
<h3 class="page-title fl"> 角色管理
    <small></small>
</h3>
<div calss="clear"></div>
<div class="row">
    <div class="col-md-12 fl">
    <a href="<?php echo Url::to(['/user/roleinfo/add']); ?>" class="btn btn-success btn-lg" style="border-radius:5px !important;background-color:#2ECC71">+添加角色</a>
    </div>
    <div class="col-md-12" style="margin-top:10px">
            <div class="portlet-body">
                    <table id="ta"
                           class="table table-striped  table-hover table-checkable order-column">
                        <thead>
                        <tr class="row" style="background-color:#eee;">
                            <th class="col-md-2" style="text-align:center;"> <div> 角色ID </div> </th>
                            <th class="col-md-3" style="text-align:center;"> <div> 角色名称 </div> </th>
                            <th class="col-md-3" style="text-align:center;"> <div> 创建时间 </div> </th>
                            <th class="col-md-4" style="text-align:center;"> <div> 操作 </div> </th>
                        </tr>
                        </thead>
                        <tbody> 
                        <?php foreach($role as $k => $v): ?>          
                            <tr class="row userleave" style="cursor:pointer">
                                <td style="text-align:center;"><div><?php echo $v['id'] ?></div> </td>
                                <td style="text-align:center;"> <div><?php echo $v['name'] ?></div> </td>
                                <td style="text-align:center;"> <div class="sureleave"><?php echo date('Y-m-d H:i:s',$v['create_time']) ?></div> </td>
                                <td style="text-align:center;"> <div><a href="<?php echo Url::to(['/user/roleinfo/update','id'=>$v['id']]); ?>" class="btn btn-primary btn-sm user_edit" data-id="">编辑</a>
					            <button class="btn btn-danger btn-sm role_delete" data-id="<?php echo $v['id'] ?>">删除</button>
                
                                </div> </td>
                            </tr>
                        <?php endforeach; ?>
                        </tbody>
                    </table>
            </div>
            <div>
				<?php
                echo LinkPager::widget([
                    'pagination' => $pages,
                    'firstPageLabel' => "首页",
                    'prevPageLabel' => '上一页',
                    'nextPageLabel' => '下一页',
                    'lastPageLabel' => '末页',
                ]);
                ?>
            </div>
    </div>
</div>
<script>
window.onload = function(){
    //办理离职
    $('.role_delete').click(function(){
        var id = $(this).attr('data-id'),
            url = '?r=user/roleinfo/delete',
            index = $(this).parent().parent().parent().index();
        layer.confirm('确认要删除吗?',{btn:['确定','取消']},function(){
            $.ajax({
                url:url,
                data:{'id':id},
                dataType:'json',
                type:'get',
                success:function(data){
                    if(data.code == 200){
                        $('.userleave').eq(index).remove();
                        layer.closeAll();
                    }else{
                        layer.msg('失败了,看看哪里错了吧!');
                    }
                }

            })
            
        })
        // alert(user_id);
    });
}
</script>